<?php

    /**
     * Calculate the reduction rate between twoo prices
     *
     * @param       Dwoo         $dwoo
     * @param       float        $originePrice
     * @param       float        $newPrice
     * @param       int          $precision
     * @return      float
     */
    function Dwoo_Plugin_get_reduction_rate(Dwoo $dwoo, $originePrice, $newPrice, $precision = 0)
    {
        $originePrice   = floatval($originePrice);
        
        if ($originePrice == 0.0) {
            $rate           = 0.0;
        } else {
            $newPrice       = floatval($newPrice);

            $rate           = ($originePrice - $newPrice) / $originePrice * 100 * -1;
        }
        
        return round($rate, $precision);
    }